<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的日常清单</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Helvetica Neue', Arial, sans-serif;
        }
        
        body {
            background-color: #f7f9fc;
            color: #333;
            line-height: 1.6;
            padding: 20px;
        }
        
        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
            overflow: hidden;
        }
        
        header {
            background: linear-gradient(135deg, #6a89cc, #4a69bd);
            color: white;
            padding: 25px 20px;
            text-align: center;
        }
        
        h1 {
            font-size: 24px;
            margin-bottom: 5px;
        }
        
        .date {
            font-size: 14px;
            opacity: 0.9;
        }
        
        .main-content {
            padding: 20px;
        }
        
        .greeting {
            margin-bottom: 20px;
            text-align: center;
            color: #555;
        }
        
        .input-section {
            display: flex;
            margin-bottom: 25px;
            gap: 10px;
        }
        
        #taskInput {
            flex: 1;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border 0.3s;
        }
        
        #taskInput:focus {
            outline: none;
            border-color: #6a89cc;
        }
        
        button {
            background: #6a89cc;
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            transition: background 0.3s;
        }
        
        button:hover {
            background: #4a69bd;
        }
        
        .filter-buttons {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }
        
        .filter-btn {
            flex: 1;
            padding: 10px;
            background: #f1f2f6;
            color: #555;
        }
        
        .filter-btn.active {
            background: #6a89cc;
            color: white;
        }
        
        .task-list {
            list-style: none;
        }
        
        .task-item {
            display: flex;
            align-items: center;
            padding: 15px;
            border-bottom: 1px solid #eee;
            transition: background 0.2s;
        }
        
        .task-item:hover {
            background: #f9fafc;
        }
        
        .task-item:last-child {
            border-bottom: none;
        }
        
        .task-checkbox {
            margin-right: 12px;
            width: 20px;
            height: 20px;
            cursor: pointer;
        }
        
        .task-text {
            flex: 1;
            font-size: 16px;
        }
        
        .task-text.completed {
            text-decoration: line-through;
            color: #999;
        }
        
        .delete-btn {
            background: #e55039;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
        }
        
        .delete-btn:hover {
            background: #eb2f06;
        }
        
        .stats {
            display: flex;
            justify-content: space-between;
            margin-top: 20px;
            padding-top: 15px;
            border-top: 1px solid #eee;
            color: #666;
            font-size: 14px;
        }
        
        .empty-state {
            text-align: center;
            padding: 30px 0;
            color: #999;
        }
        
        .empty-state img {
            width: 80px;
            opacity: 0.5;
            margin-bottom: 15px;
        }
        
        footer {
            text-align: center;
            padding: 15px;
            color: #888;
            font-size: 14px;
            border-top: 1px solid #eee;
        }
        
        @media (max-width: 480px) {
            body {
                padding: 10px;
            }
            
            .input-section {
                flex-direction: column;
            }
            
            button {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>我的日常清单</h1>
            <div class="date" id="currentDate">2023年11月15日 星期三</div>
        </header>
        
        <div class="main-content">
            <div class="greeting" id="greeting">下午好！今天有什么计划？</div>
            
            <div class="input-section">
                <input type="text" id="taskInput" placeholder="添加新任务...">
                <button id="addTaskBtn">添加</button>
            </div>
            
            <div class="filter-buttons">
                <button class="filter-btn active" data-filter="all">全部</button>
                <button class="filter-btn" data-filter="active">待完成</button>
                <button class="filter-btn" data-filter="completed">已完成</button>
            </div>
            
            <ul class="task-list" id="taskList">
                <!-- 任务将通过JavaScript动态添加 -->
            </ul>
            
            <div class="empty-state" id="emptyState">
                <img src="" alt="无任务">
                <p>暂无任务，添加一个开始吧！</p>
            </div>
            
            <div class="stats">
                <div>总计: <span id="totalTasks">0</span> 个任务</div>
                <div>已完成: <span id="completedTasks">0</span> 个</div>
            </div>
        </div>
        
        <footer>
            <p>今日事今日毕 ✨</p>
        </footer>
    </div>

    <script>
        // 获取DOM元素
        const taskInput = document.getElementById('taskInput');
        const addTaskBtn = document.getElementById('addTaskBtn');
        const taskList = document.getElementById('taskList');
        const emptyState = document.getElementById('emptyState');
        const totalTasksEl = document.getElementById('totalTasks');
        const completedTasksEl = document.getElementById('completedTasks');
        const filterBtns = document.querySelectorAll('.filter-btn');
        const currentDateEl = document.getElementById('currentDate');
        const greetingEl = document.getElementById('greeting');
        
        // 初始化任务数组
        let tasks = JSON.parse(localStorage.getItem('tasks')) || [];
        let currentFilter = 'all';
        
        // 初始化日期和问候语
        function initDateAndGreeting() {
            const now = new Date();
            const options = { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' };
            currentDateEl.textContent = now.toLocaleDateString('zh-CN', options);
            
            const hour = now.getHours();
            if (hour < 6) {
                greetingEl.textContent = '凌晨好！新的一天开始了！';
            } else if (hour < 12) {
                greetingEl.textContent = '上午好！今天有什么计划？';
            } else if (hour < 18) {
                greetingEl.textContent = '下午好！继续加油！';
            } else {
                greetingEl.textContent = '晚上好！回顾一下今天的成果吧！';
            }
        }
        
        // 保存任务到本地存储
        function saveTasks() {
            localStorage.setItem('tasks', JSON.stringify(tasks));
        }
        
        // 渲染任务列表
        function renderTasks() {
            taskList.innerHTML = '';
            
            // 根据筛选条件过滤任务
            let filteredTasks = tasks;
            if (currentFilter === 'active') {
                filteredTasks = tasks.filter(task => !task.completed);
            } else if (currentFilter === 'completed') {
                filteredTasks = tasks.filter(task => task.completed);
            }
            
            // 显示/隐藏空状态
            if (filteredTasks.length === 0) {
                emptyState.style.display = 'block';
            } else {
                emptyState.style.display = 'none';
            }
            
            // 渲染每个任务
            filteredTasks.forEach((task, index) => {
                const li = document.createElement('li');
                li.className = 'task-item';
                
                li.innerHTML = `
                    <input type="checkbox" class="task-checkbox" ${task.completed ? 'checked' : ''}>
                    <span class="task-text ${task.completed ? 'completed' : ''}">${task.text}</span>
                    <button class="delete-btn">删除</button>
                `;
                
                // 添加事件监听器
                const checkbox = li.querySelector('.task-checkbox');
                const deleteBtn = li.querySelector('.delete-btn');
                
                checkbox.addEventListener('change', () => {
                    toggleTaskCompletion(index);
                });
                
                deleteBtn.addEventListener('click', () => {
                    deleteTask(index);
                });
                
                taskList.appendChild(li);
            });
            
            // 更新统计信息
            updateStats();
        }
        
        // 更新任务统计
        function updateStats() {
            const total = tasks.length;
            const completed = tasks.filter(task => task.completed).length;
            
            totalTasksEl.textContent = total;
            completedTasksEl.textContent = completed;
        }
        
        // 添加新任务
        function addTask() {
            const text = taskInput.value.trim();
            if (text === '') return;
            
            tasks.push({
                text: text,
                completed: false,
                createdAt: new Date().toISOString()
            });
            
            taskInput.value = '';
            saveTasks();
            renderTasks();
        }
        
        // 切换任务完成状态
        function toggleTaskCompletion(index) {
            // 找到原始任务数组中的索引
            const taskId = tasks.findIndex(task => 
                task.text === tasks[index].text && 
                task.createdAt === tasks[index].createdAt
            );
            
            if (taskId !== -1) {
                tasks[taskId].completed = !tasks[taskId].completed;
                saveTasks();
                renderTasks();
            }
        }
        
        // 删除任务
        function deleteTask(index) {
            // 找到原始任务数组中的索引
            const taskId = tasks.findIndex(task => 
                task.text === tasks[index].text && 
                task.createdAt === tasks[index].createdAt
            );
            
            if (taskId !== -1) {
                tasks.splice(taskId, 1);
                saveTasks();
                renderTasks();
            }
        }
        
        // 初始化筛选按钮
        function initFilterButtons() {
            filterBtns.forEach(btn => {
                btn.addEventListener('click', () => {
                    // 移除所有按钮的active类
                    filterBtns.forEach(b => b.classList.remove('active'));
                    // 给当前点击的按钮添加active类
                    btn.classList.add('active');
                    // 更新当前筛选条件
                    currentFilter = btn.getAttribute('data-filter');
                    // 重新渲染任务
                    renderTasks();
                });
            });
        }
        
        // 初始化应用
        function initApp() {
            initDateAndGreeting();
            initFilterButtons();
            renderTasks();
            
            // 添加任务事件监听
            addTaskBtn.addEventListener('click', addTask);
            taskInput.addEventListener('keypress', (e) => {
                if (e.key === 'Enter') {
                    addTask();
                }
            });
        }
        
        // 启动应用
        initApp();
    </script>
</body>
</html>